<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>提交评论</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<h1>添加评论</h1>
<form id="commentForm">
    <label for="movieId">电影ID:</label>
    <input type="number" id="movieId" name="movie" required><br><br>

    <label for="content">评论内容:</label>
    <textarea id="content" name="content" maxlength="500" required></textarea><br><br>

    <label for="rating">评分 (1-5):</label>
    <input type="number" id="rating" name="rating" min="1" max="5" required><br><br>

    <button type="submit">提交评论</button>
</form>

<script>
    document.getElementById('commentForm').addEventListener('submit', function(event) {
        event.preventDefault(); // 防止表单默认提交

        const movieId = document.getElementById('movieId').value;
        const content = document.getElementById('content').value;
        const rating = document.getElementById('rating').value;

        // 使用 Axios 发送 POST 请求
        axios.post('http://localhost:8080/comment/submitComment', {
            movie: movieId,
            content: content,
            rating: rating
        })
            .then(response => {
                alert("评论提交成功: " + response.data.content);
            })
            .catch(error => {
                alert("提交评论时出错: " + (error.response.data || error.message));
            });
    });
</script>
</body>
</html>
